package shujia.day08;

/*
    String类中的构造方法：
        public String()
        public String(byte[] bytes)
        public String(byte[] bytes,int offset,int length)
        public String(char[] value)
        public String(char[] value,int offset,int count)
        public String(String original)

 */
public class StringDemo2 {
    public static void main(String[] args) {
        //public String()
        String s1 = new String();
        System.out.println("s1: "+s1);
        System.out.println("-----------------------");
        //public String(byte[] bytes)  将字节数组转成一个字符串
        byte[] bytes = {97,65,48,98,99};
        String s2 = new String(bytes);
        System.out.println("s2: "+s2);
        System.out.println("-----------------------");
        //public String(byte[] bytes,int index,int length)  截取字节数组一部分转成字符串
        String s3 = new String(bytes, 1, 3);
        System.out.println("s3: "+s3);
        System.out.println("-----------------------");
        //public String(char[] value) 将字符数组转成一个字符串
        char[] chars = {'我','爱','刘','亦','菲'};
        String s4 = new String(chars);
        System.out.println("s4: "+s4);
        System.out.println("-----------------------");
        //public String(char[] value,int offset,int count) 截取字符数组一部分转成字符串
        String s5 = new String(chars,2,3);
        System.out.println("s5: "+s5);
        System.out.println("-----------------------");
        //public String(String original)
        String s6 = new String("hello");
        System.out.println("s6: "+s6);
        System.out.println("-----------------------");
        String s = new String("hello");
        String s7 = "hello";
        System.out.println(s==s7);

    }
}
